from selenium.webdriver.common.by import By
from pages.base_page import BasePage


class MessagePage(BasePage):
    write_locator = (By.ID, "send")
    select_locator = (By.CSS_SELECTOR, "#ta1 > input")
    text_locator = (By.NAME, "content")
    send_locator = (
        By.CSS_SELECTOR, "#dialog-message-send > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")
    succeed_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")

    # 点击写信
    def write_message(self):
        self.driver.find_element(*self.write_locator).click()

    # 点击全部选择
    def select_all(self):
        self.driver.find_element(*self.select_locator).click()

    # 输入站内信内容
    def input_content(self, content):
        self.driver.find_element(*self.text_locator).send_keys(content)

    # 点击发送
    def send_message(self):
        self.driver.find_element(*self.send_locator).click()

    # 获取站内信页面的发送成功文本
    def gain_succeed_text(self):
        return self.driver.find_element(*self.succeed_locator).text
